package com.justnow.offer;

import java.util.Map;
import java.util.Stack;

/**
 * @author justnow
 * Created on 2020-09-14
 * Description
 */
public class Shunfeng01 {
    public int longesetValidParenteses(String s) {

        int maxString = 0;

        Stack<Integer> stack = new Stack<>();

        stack.push(-1);

        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '(') {
                stack.push(i);
            } else {
                stack.pop();
                if (stack.empty()) {
                    stack.push(i);
                } else {
                    maxString = Math.max(maxString, i - stack.peek());
                }
            }

        }
        return maxString;
    }
}
